﻿@page
@model NoticeClient.Pages.TaskModel
@{
    ViewData["Title"] = "任务列表";
}


<div class="weui-cells weui-cells_form">
    <a href="/privacy" class="weui-cell weui-cell_link">
        <div class="weui-cell__bd">新增任务</div>
    </a>
    <div class="weui-cell">
        <div class="weui-cell__hd"><label for="status" class="weui-label">状态</label></div>
        <div class="weui-cell__bd">
            <select class="weui-select" id="status" onchange="loadData()">
                <option value="0">待发送</option>
                <option value="1">已发送</option>
            </select>
        </div>
    </div>
</div>
<div class="notice-list">

</div>

@section Scripts{
    <script type="text/javascript">
        loadData();

        function loadData() {
            ajax({

                url: "/Tasks/QueryAll",
                data: {
                    "FilterType": 1,
                    "FilterRules": [{
                        "CompareType": 1, "Field": "Status", "Value": $("#status").val()
                    }],
                    "FilterGroups": []
                },
                type: "POST",
                success: function (data) {
                    $(".notice-list").html('');
                    var html = '<div class="weui-panel__bd">';
                    $.each(data, function (i, o) {
                        html += '<div class="weui-media-box weui-media-box_text">';
                        html += '<h4 class="weui-media-box__title">' + o.taskName + '</h4>';
                        var taskType = o.taskType == 0 ? "触发1次" : "循环触发";
                        var taskRunTypeName = "";
                        switch (o.taskRunType) {
                            case 1: taskRunTypeName = "一";
                                break;
                            case 2: taskRunTypeName = "二";
                                break;
                            case 3: taskRunTypeName = "三";
                                break;
                            case 4: taskRunTypeName = "四";
                                break;
                            case 5: taskRunTypeName = "五";
                                break;
                            case 6: taskRunTypeName = "六";
                                break;
                            case 7: taskRunTypeName = "日";
                                break;
                            case 0: taskRunTypeName = "每天";
                        }
                        var TaskRunType = (o.TaskRunType == 0 ? "每天" : ("每周" + taskRunTypeName));
                        var TaskStartType = o.taskStartType == 0 ? "直接发送内容" : "执行任务";
                        html += '<p class="weui-media-box__desc">发送时间: ' + new Date(o.startDate).DateFormat("yyyy-MM-dd") + ' ' + (o.startHour < 9 ? '0' + o.startHour : o.startHour) + ':' + (o.startMinute < 9 ? '0' + o.startMinute : o.startMinute) + '</p>';
                        html += '<p class="weui-media-box__desc">触发类型: ' + taskType + ' </p>';
                        if (o.taskType == 1)
                            html += '<p class="weui-media-box__desc">循环次数: ' + TaskRunType + ' </p>';
                        html += '<p class="weui-media-box__desc">执行类型: ' + TaskStartType + ' </p>';
                        html += '<p class="weui-media-box__desc">消息内容: ' + o.content + ' </p>';
                        html += '<p class="weui-media-box__desc">指定接收人: ' + o.received + ' </p>';
                        html += '<ul class="weui-media-box__info">' +
                            '<li class="weui-media-box__info__meta  pull-right">';
                        html += '<a onclick="updatetask(\'' + (o._Id) + '\')">编辑</a>&nbsp;&nbsp;';
                        html += '<a onclick="deltask(\'' + (o._Id) + '\')">删除</a>';
                        html += '</li></ul>';
                        html += "</div>";


                    })
                    html += '</div>';
                    $(".notice-list").html(html);
                }

            })

        }
        function updatetask(id) {
            window.location.href = '/privacy?id=' + id;
        }
        function deltask(id) {
            $.confirm("您确定要删除吗?", "确认删除?", function () {
                ajax({
                    url: "/Tasks/Delete?id=" + id,
                    type: "POST",
                    success: function (data) {
                        if (data.type == 200) { $.toast(data.message); }
                        loadData()
                    }
                })
            }, function () {
                //取消操作
            });


        }

    </script>
}
